package hengtiansoft.com.myapplication;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

/**
 * Created by lu on 16/3/11.
 */
public class SQLiteActivity extends BaseActivity {
    Button ok;
    EditText title, message;
    SQLiteDatabase db;
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.sqlite);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initView() {
        ok = (Button) findViewById(R.id.ok);
        ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // TODO: 16/3/11  点击按钮插入数据库
                getMsgTodb();
            }
        });
        title = (EditText) findViewById(R.id.enter);
        message = (EditText) findViewById(R.id.message);
        listView = (ListView) findViewById(R.id.listView);
    }

    @Override
    public void initData() {
        //创建数据库..
        db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString() + "/my.db3", null);
    }

    private void getMsgTodb() {
        String titleText = title.getText().toString();
        String msg = message.getText().toString();

        db.execSQL("insert into news_inf values(null,?,?)", new String[]{titleText, msg});
//        Cursor cursor=db.rawQuery()
    }

}
